import java.util.HashMap;

public class Main {

    public static void main(String[] args) {
        int[] nums={1,2,3,4,5,6,7};
        Main main = new Main();
//        System.out.println(main.majorityElement(nums));
    main.rotate(nums,3);
    }
    public int majorityElement(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int n=nums.length;
        if(n==1)return  nums[0];
        for (int num : nums) {
            if (map.containsKey(num)) {
                map.put(num, map.get(num)+1);
                if(map.get(num)>=(n+1)/2){
                    return num;
                }
            }else{
                map.put(num, 1);
            }
        }
        return -1;
    }
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
    }

    public void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start += 1;
            end -= 1;
        }
    }

}